package com.yunhai.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.tms.TmsStoreCategoryEntity;
import com.yunhai.model.vo.tms.TmsStoreCategoryQuery;
import com.yunhai.model.vo.tms.TmsStoreCategoryVo;
import com.yunhai.store.service.TmsStoreCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/storeCategory")
public class TmsStoreCategoryController {

    @Resource
    private TmsStoreCategoryService tmsStoreCategoryService;


    /**
     * 获取 TmsStoreCategory 分页列表
     */
    @GetMapping("/pagination")
    public Ret getTmsStoreCategoryPagination(PaginationVo paginationVo, TmsStoreCategoryQuery tmsStoreCategoryQuery ) throws Exception {
        IPage page = tmsStoreCategoryService.getTmsStoreCategoryPagination(paginationVo, tmsStoreCategoryQuery );
        return Ret.toPage(page);
    }


    /**
     * 获取 TmsStoreCategory 所有数据
     */
    @GetMapping("/allList")
    public Ret getTmsStoreCategoryAllList( TmsStoreCategoryQuery tmsStoreCategoryQuery ) throws Exception {
        List<TmsStoreCategoryEntity> list = tmsStoreCategoryService.getTmsStoreCategoryAllList( tmsStoreCategoryQuery );
        return Ret.ok(list);
    }


    /**
     * 获取 TmsStoreCategory 详情
     */
    @GetMapping("/{id}")
    public Ret getTmsStoreCategoryDetail(@PathVariable Long id) throws Exception {

        TmsStoreCategoryEntity tmsStoreCategory = tmsStoreCategoryService.getTmsStoreCategoryDetail(id);
        return Ret.ok(tmsStoreCategory);
    }


    /**
     * 新增 TmsStoreCategory
     * */
    @PostMapping("")
    public Ret addTmsStoreCategory(@RequestBody TmsStoreCategoryVo tmsStoreCategoryVo) throws Exception {

        tmsStoreCategoryService.addTmsStoreCategory(tmsStoreCategoryVo);
        return Ret.ok();
    }


    /**
     * 更新 TmsStoreCategory
     * */
    @PutMapping("")
    public Ret updateTmsStoreCategory(@RequestBody TmsStoreCategoryVo tmsStoreCategoryVo) throws Exception {

        tmsStoreCategoryService.updateTmsStoreCategory(tmsStoreCategoryVo);
        return Ret.ok();
    }


    /**
     * 删除 TmsStoreCategory
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveTmsStoreCategory( @RequestBody List<Long> ids ) throws Exception {

        tmsStoreCategoryService.batchRemoveTmsStoreCategory(ids);
        return Ret.ok();
    }
}
